package ui;

import java.util.Collection;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Composite;

import each_class.Album;
import each_class.SongClass;
import ui.global.Current;

public class MusicListUI extends AbstractUI {

	private MusicView musicView;
	public MusicListUI(Composite parent, int style) {
		super(parent, style);
		title.setText("榜单");
		
		musicView = new MusicView(this, SWT.NONE) {
			@Override
			public void loadMusic(Collection<SongClass> musicList) {
				for (SongClass music : musicList) {
					new MusicViewItem(scrolledView, SWT.NONE) {
						public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
							if (e.button == 3) {
								dispose();
								getParent().layout();
							}
						};
					}.initail(music);
					scrolledView.downcount += scrolledView.scrollHeight;		

				}
				scrolledView.layout();
			}
		};
		musicView.setBounds(0, 123, 1210, 513);
		
		TabFolderItem musicItem =  new TabFolderItem(tabFolder, musicView);
		tabFolder.setFont(new Font(getDisplay(), "Microsoft YaHei UI", 18, SWT.NORMAL));
		musicItem.setText("歌曲");
		tabFolder.setCurrentTabFolderItem(musicItem);
		tabFolder.getCurrentTabFolderItem().active();
		tabFolder.layout();
	}
	
	public void initail(List<SongClass> musicList) {
		musicView.dispose();
		musicView = new MusicView(this, SWT.NONE);
		musicView.setBounds(0, 123, 1210, 513);
		musicView.loadMusic(musicList);
	}

	@Override@Deprecated
	public void active() {
	}
	
	public void active(Album album) {
		Current.getUI().setVisible(false);
		Current.setUI(this);
		if(LeftButton.currentButton != null) {
			LeftButton.currentButton.deactive();
			LeftButton.currentButton = null;
		}
		title.setText(album.getAlbm_name());
		setVisible(true);
		List<SongClass> musicList = album.getsClasses();
		if (musicList != null) {
			initail(musicList);
		}
	}
	
	public void active(List<SongClass> musicList) {
		Current.getUI().setVisible(false);
		Current.setUI(this);
		if(LeftButton.currentButton != null) {
			LeftButton.currentButton.deactive();
			LeftButton.currentButton = null;
		}
		setVisible(true);
		if (musicList != null) {
			initail(musicList);
		}
	}
}
